package DynamicProxy;

/**
 * Created by rzd on 2017/4/6.
 */
public class ProxyTest {
    public static void main(String[] args) {
test2();
    }
    public static void test1()
    {
        //真实主题角色
        SayByeImpl sayByeImpl = new SayByeImpl();

        /*
         * //不使用代理的情况
         *  sayByeImpl.sayGoodBye("我要离婚！");
         *  sayByeImpl.sayByeBye();
         */

        //代理主题角色,这里用代理主题和真实主题实现的同样接口类来接收创建的代理主题，就是创建一个目标类
        SayGoodBye sayGoodBye = (SayGoodBye) new JDKProxy().createProxyInstance(sayByeImpl);
        SayByeBye sayByeBye = (SayByeBye) new JDKProxy().createProxyInstance(sayByeImpl);
        sayGoodBye.sayHello("gg");
//        sayGoodBye.sayGoodBye("受不了了，我要离婚！");
//        System.out.println("00000000000000000000000000000000000000000000000");
//        sayByeBye.sayByeBye();
    }
    public static void test2()
    {
        //真是主题角色
        SayHello sayHello = new SayHello();
        //sayHello.say("嗨！你好啊！");

        //创建了一个 目标类的对象 ，jdk动态代理中创建的是接口类对象，cglib由于不实现任何接口，所以直接创建一个目标类的对象
        SayHello sh = (SayHello) new CglibProxy().createProxyInstance(sayHello);
        sh.say("嗨！你好啊！");
    }

}
